{% extends 'course-video.html' %}

{% block leftbox %}
<div class="mod-tab-menu">
        <ul class="course-menu clearfix">
            <li><a  class=" {% ifequal tag 'info' %}ui-tabs-active active{% endifequal %}" id="learnOn" href="{% url 'course:course_info' course.id %}"><span>章节</span></a></li>
            <li><a  class=" {% ifequal tag 'comment' %}ui-tabs-active active{% endifequal %}" id="commentOn" class="" href="{% url 'course:course_comment' course.id %}"><span>评论</span></a></li>
        </ul>
    </div>
<!--发布评论-->
<div id="js-pub-container" class="issques clearfix js-form">
    <div class="wgt-ipt-wrap pub-editor-wrap " id="js-pl-input-fake">
        <textarea id="js-pl-textarea" class="" placeholder="扯淡、吐槽、表扬、鼓励……想说啥就说啥！" ></textarea>
    </div>
    <input type="button" id="js-pl-submit" class="pub-btn" data-cid="452" value="发表评论">
    <p class="global-errortip js-global-error"></p>
</div>
<div id="course_note">
    <ul class="mod-post" id="comment-list">
        {% for items in course.get_course_comment %}
            <li class="post-row">
                <div class="media">
                    <span target="_blank"><img src='{{ MEDIA_URL }}{{ items.user.image }}' width='40' height='40' /></span>
                </div>
                <div class="bd">
                    <div class="tit">
                        <span target="_blank">{{ items.user.username }}</span>
                    </div>
                    <p class="cnt">{{ items.comments }}</p>
                    <div class="footer clearfix">
                        <span title="创建时间" class="l timeago">时间：{{ items.add_time }}</span>
                    </div>
                </div>
            </li>        
        {% endfor %}
    </ul>
</div>    
{% endblock leftbox %}


{% block commentjs %}
<script>
$('#js-pl-submit').on('click', function(){
    var comments = $("#js-pl-textarea").val()
    if(comments == ""){
        alert("评论不能为空")
        return
    }
    $.ajax({
        cache: false,
        type: "POST",
        url: '{% url 'operation:operation_add_comment' %}',
        data:{'course_id':{{ course.id }}, 'comments':comments},
        async: true,
        beforeSend:function(xhr, settings){
            xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
        },
        success: function(data) {
            if(data.status == 'fail'){
                if(data.msg == '用户未登录'){
                    window.location.href="login.html";
                }else{
                    alert(data.msg)
                }

            }else if(data.status == 'success'){
                //window.location.reload();//刷新当前页面.
            }
        },
    });
}); 
</script>
{% endblock commentjs %}
    
    